|
|
|
|
|
|
|
Listing 5.18. Coding the WriteProperties event of the VText control. |
|
|
|
|
|
|
|
|
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
'
' save design-time property values
'
With PropBag
Call .WriteProperty("UpperCase", m_UpperCase, m_def_UpperCase)
Call .WriteProperty("Digits", m_Digits, m_def_Digits)
Call .WriteProperty("Numeric", m_Numeric, m_def_Numeric)
'
Call .WriteProperty("Text", Text1.Text, UserControl.Name)
End With
'
End Sub |
|
|
|
|
|
|
|
|
All read and write operations are performed using the PropBag ("Property Bag") object. This object contains the correct settings for all the properties at any given time. Notice that the WriteProperty method of the PropBag object takes three parameters: property name, current value, and default value. The default value is used if the current value is set to null. |
|
|
|
|
| |
|
|
|
|
Although the default value is an optional parameter for the WriteProperty method, you should use it. Values are saved only if they are different from the default value. If you include default values for all your properties, you can reduce the size of the file needed to store your custom properties. |
|
|
|
|
|
|
|
|
|
|
Next, add the code in Listing 5.19 to the UserControl_ReadProperties event. This ensures that Visual Basic runtime loads the property values stored by in the WriteProperties event by Visual Basic design time. |
|
|
|
|
|
|
|
|
Listing 5.19. Coding the ReadProperties event for the VText control. |
|
|
|
|
|
|
|
|
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
'
' read design-time property values
'
With PropBag
m_UpperCase = .ReadProperty("UpperCase", m_def_UpperCase)
m_Digits = .ReadProperty("Digits", m_def_Digits)
m_Numeric = .ReadProperty("Numeric", m_def_Numeric)
'
Text1.Text = .ReadProperty("Text", UserControl.Name) |
|
|
|
|
|